﻿using System;
using System.Windows;
using MyFloridaHouse.ServiceConn.DistrBldrSvcRef;

namespace MyFloridaHouse.libSvOpenDistricts.DataService
{
    public delegate void ServiceDALGetLayerDataDictionariesCompletedEventHandler(DataDictionarySTO sto);

    public partial class ServiceDAL
    {
        public static event ServiceDALGetLayerDataDictionariesCompletedEventHandler GetLayerDataDictionariesCompleted;

        public void GetLayerDataDictionaries()
        {
            try
            {
                //MyDistrictBuilderServiceClient proxy = new MyDistrictBuilderServiceClient(myRelativeBinding, myRelativeCensusDataServiceAddress);
				var proxy = new DistrBldrClient(_relativeBindingName);
                proxy.GetLayerDataDictionaryCompleted += ServiceGetLayerDataDictionaries;
                proxy.GetLayerDataDictionaryAsync();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }


        private void ServiceGetLayerDataDictionaries(object sender, GetLayerDataDictionaryCompletedEventArgs args)
        {
            if (!IsError("GetLayersCompleted", args.Error, args.Result, args.Result.errorMessage))
            {
                RaiseGetLayerDataDictionariesCompleted(this, args.Result);
            }
        }

        private static void RaiseGetLayerDataDictionariesCompleted(object sender, DataDictionarySTO sto)
        {
            if (GetLayerDataDictionariesCompleted != null)
            {
                GetLayerDataDictionariesCompleted(sto);
            }
            else
            {
                // todo: Log this error
                throw (new NotImplementedException("No Subscribers to ServiceDALGetLayerDataDictionariesCompleted Event"));
            }
        }

    }
}
